package cn.tedu.csmall.business.service.impl;

import cn.tedu.csmall.business.service.IBusinessService;
import cn.tedu.csmall.commons.pojo.order.dto.OrderAddDTO;
import cn.tedu.csmall.order.service.IOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BusinessServiceImpl implements IBusinessService {

    //business模块远程调用order模块中的方法，需要order的接口的实现类
    //@DubboReference获取业务逻辑层实现类对象
    @DubboReference
    private IOrderService dubboOrderService;

    @Override
    @GlobalTransactional
    public void buy() {
        //模拟一下购买业务
        //创建一个OrderAddDTO，并赋值
        OrderAddDTO orderAddDTO = new OrderAddDTO();
        orderAddDTO.setUserId("UU100");
        orderAddDTO.setCommodityCode("PC300");
        orderAddDTO.setCount(5);
        orderAddDTO.setMoney(500);
        //模拟购买，只要在控制台输出即可
        log.info("新增订单的信息为：{}",orderAddDTO);
        //调用Order模块
        dubboOrderService.orderAdd(orderAddDTO);
        //模拟远程调用，先在控制台输出看结果
        log.info("新增订单的信息为：{}",orderAddDTO);
    }
}
